package com.kuang.controller;

import com.kuang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController  //RestController 纯天然屏蔽视图解析器   Controller  进入视图解析器
public class AjaxController {

    @RequestMapping("t1")
    public  String test(){
        return "hello";
    }

    @RequestMapping("/a1")
    public void a1(String name , HttpServletResponse response) throws IOException {
        System.out.println("a1:param->"+name);
        if ("zls".equals(name)){
            response.getWriter().println("true");
        }else {
            response.getWriter().println("false");
        }
    }

    @RequestMapping("/a2")
    public List<User> a2(){
        ArrayList<User> userList = new ArrayList<>();

        //添加参数
        userList.add(new User("张立帅说故事",1,"男"));
        userList.add(new User("张立帅说历史",1,"女"));
        userList.add(new User("张立帅说军事",1,"女博士"));

        return userList;
    }

    @RequestMapping("/a3")
    public String a3(String name , String pwd){
        String msg = "";
        if (name != null){
            //admin 这个数据应该在数据库中查找
            if (name.equals("admin")){
                msg = "ok";
            }else {
                msg = "用户名有错误";
            }
        }

        if (pwd != null){
            //123456 这个数据应该在数据库中查找
            if (pwd.equals("123456")){
                msg = "ok";
            }else {
                msg = "密码有错误";
            }
        }
        return  msg;
    }

}
